package com.bcu.team.comment.controller;

import com.bcu.team.comment.entity.Collection;
import com.bcu.team.comment.entity.Message;
import com.bcu.team.comment.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.List;

@Api(tags = "收藏模块")
@RestController
@RequestMapping("/api/collection")
public class CollectionController {

    @Resource
    private CollectionService collectionService;


    @ApiOperation(value = "根据用户id获取收藏")
    @GetMapping(value = "/getcollectionByUserId")
    public List<Collection> getCollectionsByUserId(Integer userId){
        return collectionService.getCollectionsByUserId(userId);
    }

    @ApiOperation(value = "添加收藏")
    @PostMapping(value = "/add")
    public Message addCollection(Collection collection){
        return collectionService.addCollection(collection);
    }

    @ApiOperation(value = "取消收藏歌曲")
    @DeleteMapping(value = "/delayCollectedSong")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "songId",value = "歌曲id",required = true),
            @ApiImplicitParam(name = "userId",value = "用户id",required = true)
    })
    public Message delayCollectedSong(@RequestParam(value = "songId") Integer songId,
                                       @RequestParam(value = "userId") Integer userId){
        return collectionService.delayCollectedSong(songId,userId);
    }

    @ApiOperation(value = "判断用户是否收藏该歌曲")
    @GetMapping(value = "/isUserCollectedSong")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "songId",value = "歌曲id",required = true),
            @ApiImplicitParam(name = "userId",value = "用户id",required = true)
    })
    public boolean isUserCollectedSong(@RequestParam(value = "songId") Integer songId,
                                       @RequestParam(value = "userId") Integer userId){
        return collectionService.isUserCollectedSong(songId,userId);
    }

}
